#include <iostream>
#include <leveldb/db.h>
#include <string>
#include <memory>
#include <leveldb/write_batch.h>

#define DB_PATH "/tmp/leveldb"

int main(int argc, char **argv)
{
	std::cout << DB_PATH << std::endl;
	leveldb::Options opts;
	opts.create_if_missing = true;

	leveldb::DB *dbptr = nullptr;

	leveldb::Status status = leveldb::DB::Open(opts, DB_PATH, &dbptr);
	if (status.ok())
	{
		std::cout << "leveldb open success" << std::endl;
	}
	else
	{
		std::cout << "failed to open db" << status.ToString() << std::endl;
	}

	std::unique_ptr<leveldb::DB> safedb{dbptr};

	leveldb::WriteOptions write_opt;
	write_opt.sync = false;
	leveldb::ReadOptions read_opt;
	read_opt.verify_checksums = false;

	// batch process
	leveldb::WriteBatch batch;
	batch.Put("hello", "world");
	batch.Put("xxx", "videos");
	batch.Put("cat", "meme");
	batch.Put("wowo", "gigity");
	batch.Delete("wowo");

	status = safedb->Write(write_opt, &batch);
	std::cout << status.ToString() << std::endl;

	

	return 0;
}
